//
//  BrowseScrollView.m
//  浏览界面
//
//  Created by lanou on 15/12/18.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "BrowseScrollView.h"
#import "TaplmageView.h"
#import "UIImageView+AFNetworking.h"
#define kWidth [UIScreen mainScreen].bounds.size.width

@implementation BrowseScrollView

- (instancetype)initWithFrame:(CGRect)frame targer:(id)targer action:(SEL)action imageArray:(NSArray *)imageArray timer:(NSTimeInterval)timer selector:(SEL)selector {
    self = [super initWithFrame:frame];
    if (self) {
        self.showsHorizontalScrollIndicator = NO;
        NSMutableArray *insterImageArray = [NSMutableArray arrayWithArray:imageArray];
        [insterImageArray insertObject:imageArray.firstObject atIndex:insterImageArray.count];
        self.contentSize = CGSizeMake(insterImageArray.count * kWidth, 0);
        self.bounces = NO;
        self.delegate = targer;
        self.pagingEnabled = YES;
        self.contentOffset = CGPointMake(kWidth, 0);
        for (int i = 0; i < insterImageArray.count; i ++) {
            TaplmageView *tapImage = [[TaplmageView alloc]initWithFrame:(CGRectMake(i * kWidth + 5, 10, kWidth - 10, self.bounds.size.height - 20)) targer:targer action:action];
            [tapImage setImageWithURL:[NSURL URLWithString:insterImageArray[i]]];
            [self addSubview:tapImage];
        }
        [NSTimer scheduledTimerWithTimeInterval:timer target:targer selector:selector userInfo:nil repeats:YES];
    }
    return self;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
